    import 'dart:io';

    void main() {
      print("Welcome to Budget Management System!");

      List<Map<String, double>> incomeList = [];
      List<Map<String, double>> expenseList = [];

      while (true) {
        print("\n--- Menu ---");
        print("1. Add Income");
        print("2. Add Expense");
        print("3. View Summary");
        print("4. Exit");

        stdout.write("Enter your choice: ");
        String? choice = stdin.readLineSync();

        if (choice == "1") {
          stdout.write("Enter income description: ");
          String desc = stdin.readLineSync()!;

          stdout.write("Enter amount: ");
          double? amount = double.tryParse(stdin.readLineSync()!);

          if (amount != null && amount >= 0) {
            incomeList.add({desc: amount});
            print("Income added successfully.");
          } else {
            print("❌ Invalid amount!");
          }

        } else if (choice == "2") {
          stdout.write("Enter expense description: ");
          String desc = stdin.readLineSync()!;

          stdout.write("Enter amount: ");
          double? amount = double.tryParse(stdin.readLineSync()!);

          if (amount != null && amount >= 0) {
            expenseList.add({desc: amount});
            print("Expense added successfully.");
          } else {
            print("❌ Invalid amount!");
          }

        } else if (choice == "3") {
          double totalIncome = 0;
          double totalExpenses = 0;

          incomeList.forEach((entry) {
            totalIncome += entry.values.first;
          });

          expenseList.forEach((entry) {
            totalExpenses += entry.values.first;
          });

          double net = totalIncome - totalExpenses;

          print("\n--- Summary ---");
          print("Total Income: \$${totalIncome}");
          print("Total Expenses: \$${totalExpenses}");

          if (net >= 0) {
            print("Your net profit is \$${net}");

            double tax = net > 0 ? net * 0.15 : 0;
            print("Tax to be paid: \$${tax}");

          } else {
            print("Your net loss is \$${net.abs()}");
          }

        } else if (choice == "4") {
          print("Exiting Budget Management System...");
          break;

        } else {
          print("❌ Invalid choice!");
        }
      }
    }
